package com.tanhua.server.controller;

import com.tanhua.server.service.AnnouncementService;
import com.tanhua.server.service.IMService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class IMController {

    @Autowired(required = false)
    private IMService imService;
    @Autowired
    private AnnouncementService announcementService;

    /**
     * 接口名称：根据环信id查询用户信息\
     * 接口路径：GET/messages/userinfo
     */
    @GetMapping("/userinfo")
    public ResponseEntity<Object> getHuanxinUserInfo(Long huanxinId) {
        return imService.getHuanxinUserInfo(huanxinId);
    }


    /**
     * 接口名称：联系人添加
     * 接口路径：POST/messages/contacts
     */
    @PostMapping("/contacts")
    public ResponseEntity<Object> addContact(@RequestBody Map<String, Integer> paramMap) {
        Integer friendUserId = paramMap.get("userId");
        return imService.addContact(friendUserId);
    }


    /**
     * 接口名称：联系人列表
     * 接口路径：GET/messages/contacts
     */
    @GetMapping("/contacts")
    public ResponseEntity<Object> queryContractList(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize, String keyword) {
        if (page == 2) {
            page = 1;
        }
        return imService.queryContractList(page, pagesize, keyword);
    }

    /**
     * 获取点赞消息列表
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("likes")
    public ResponseEntity<Object> likesMessagePage(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {
        return imService.likesMessagePage(1, page, pagesize);

    }

    /**
     * 获取评论消息列表
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("comments")
    public ResponseEntity<Object> commentsMessagePage(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {
        return imService.likesMessagePage(2, page, pagesize);

    }

    /**
     * 获取喜欢消息列表
     *
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("loves")
    public ResponseEntity<Object> lovesMessagePage(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pagesize) {
        return imService.likesMessagePage(3, page, pagesize);

    }

    /**
     * 接口名称：公告列表
     * 接口路径：GET/messages/announcements
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/announcements")
    public ResponseEntity<Object> announcements(@RequestParam(defaultValue = "1") Integer page,
                                                @RequestParam(defaultValue = "10") Integer pagesize) {
        return announcementService.findByPage(page, pagesize);
    }

}
